package ru.agiledev.aos.core;

import ru.agiledev.aos.commons.dto.SearchEntry;
import ru.agiledev.aos.commons.dto.SemanticQuery;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by a.kirillov
 * Date: 2/14/12 Time: 9:39 PM
 */
public class QueriesRunner {
        SemanticQuery query;
    public QueriesRunner(SemanticQuery query){
        this.query = query;
    }

    private volatile List<SearchEntry> entries = new ArrayList<SearchEntry>();

    public List<SearchEntry> runQueries(){
        List<String> queries = query.getQueries();
        for(String q:queries){
            SearchThread thread = new SearchThread(q, this);
            thread.start();
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return entries;
    }


    public void registerResult(List<SearchEntry> entries){
        synchronized (this.entries){
            this.entries.addAll(entries);
        }
    }


}
